<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page contentType="text/html; charset=UTF-8" language="java"
	import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/base.jsp"%>
<%@ taglib prefix="d" uri="/doone-comm-ui-tags"%>

<html>
	<head>
		<title>企业信息管理</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
		<link type="text/css" href="<%=path%>/manage/css/layout.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="<%=path%>/manage/css/Tooltip.css" />
        <link type="text/css" href="<%=path%>/manage/css/new_style.css" rel="stylesheet" />
        
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery-1.4.4.min.js"></script>

		<script type="text/javascript"
			src="<%=path%>/manage/js/easyTooltip.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery-ui-1.8.11.custom.min.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.wysiwyg.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/hoverIntent.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/superfish.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/custom.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/My97DatePicker/WdatePicker.js"></script>
		<%-- 验证js Start --%>
		<script type="text/javascript" src="<%=path%>/manage/js/Tooltip.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.validate.min.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.validate.methods.min.js"></script>
		<script type="text/javascript"
			src="<%=path%>/manage/js/jquery.validate.defaults.js"></script>
		<script type="text/javascript" src="<%=path%>/manage/js/errorTip.js"></script>
</head>

	<script type="text/javascript">
	//应用编辑	
	function editEnter(intEnterpId) {
		$.ajax({
			url : root + '/enterprise/goEditEnterprise.action',
			method : 'post',
			dataType : 'json',
			data : {
				'intEnterpId' : intEnterpId
			},
			success : function(data) {
				//给form的文本赋值
				//企业名称		
				$("#varEnterpName").attr("value", data.varEnterpName);
				//企业行业类型
				$("#intTypeId").attr("value", data.intTypeId);
				//爱企业发送姓名
				$("#varEnterpLegalPerson").attr("value",
						data.varEnterpLegalPerson);
				//企业许可证URL
				if(data.varEnterpLicenseImgUrl==null){
					$("#imgFile").hide();
				} else {
					$("#imgFile").attr("src", data.varEnterpLicenseImgUrl);
				}
				//联系电话
				$("#varEnterpPhonenum").attr("value", data.varEnterpPhonenum);
				//企业邮箱
				$("#varEnterpEmail").attr("value", data.varEnterpEmail);
				//企业联系地址
				$("#varEnterpAddress").attr("value", data.varEnterpAddress);

				$("#intEnterpId").attr("value", data.intEnterpId);

				//打开dialog
				$("#openEnterDialog").dialog("open");
			},
			error : function(err) {
				if (err.responseText != '')
					alert(err.responseText);
				else
					alert("请求失败！");
			}
		});
	}
	//企业信息删除
	function delEnter(intEnterpId) {
		if (confirm("慎重考虑是否确定删除该记录?删除后无法查看该条记录！！！")) {
			$.ajax({
				url : root + '/enterprise/dodelEnterprise.action',
				method : 'post',
				data : {
					'intEnterpId' : intEnterpId
				},
				success : function(data) {

					window.location.href = root
							+ '/enterprise/goEnterprise.action';
				},
				error : function(err) {
					if (err.responseText != '')
						alert(err.responseText);
					else
						alert("请求失败！");
				}
			});
		}
	}
	//检测文件格式
	var flag = true;
	function validateFile(obj) {       
		
		    var filepath = obj.value;
		
			var fileArr = filepath.split("\\");
			var fileTArr = fileArr[fileArr.length - 1].toLowerCase().split(".");
			var filetype = fileTArr[fileTArr.length - 1];
			if (filetype != "jpg" && filetype != "png") {
				$(obj).addErrorMessage("必须上传jpg、png格式的文件");					
				flag = false;
			} else {
				 $(obj).removeErrorMessage();	
				 flag = true;
			}
	}
	$(document).ready(function() {
		//验证
		var editEnterForm = $("#editEnterForm").validate({
			rules : {
				"enterpriseDto.varEnterpName" : {
					required : true
				},
				"enterpriseDto.intTypeId" : {
					required : true
				},
				"enterpriseDto.varEnterpLegalPerson" : {
					required : true
				},

				"enterpriseDto.varEnterpPhonenum" : {
					required : true
				}

			},
			messages : {
				"enterpriseDto.varEnterpName" : {
					required : "企业名称必填"
				},
				"enterpriseDto.intTypeId" : {
					required : "行业类型必须选择"
				},
				"enterpriseDto.varEnterpLegalPerson" : {
					required : "企业名称必填"
				},

				"enterpriseDto.varEnterpPhonenum" : {
					required : "联系电话必填"
				}

			}
		});
		//加载dialog
		$("#openEnterDialog").dialog({
			autoOpen : false,
			width : 800,
			height : 350,
			modal : true,
			title : '企业信息编辑',
			buttons : {
				"保存" : function() {
					if (!editEnterForm.valid()) {
					
						alert("数据验证未通过，无法保存");
					} else  if(!flag){
					    alert("上传文件格式错误");
					}else{
						$("#editEnterForm").submit();
						$(this).dialog("close");
					}
					//$("#searchBtn").click();
				},
				"取消" : function() {
					$(this).dialog("close");
					$("#editEnterForm")[0].reset();
				}
			},
			close : function() {
				$("#editEnterForm")[0].reset();
			}
		});

		//企业检索处理
		$("#searchBtn").click(function() {
			$("#searchForm").submit();
		});
	});

	function getEnterShop(intEnterpId) {
		window.location.href = root + '/enterShop/getEnterShopinfo.action';
	}
</script>

	<body>
		<div>
			<p class="sitemap">
				当前位置：内容管理 > 企业信息管理
			</p>
			<h1>
				企业信息管理
			</h1>
			<div>
				<!-- Tabs -->
				<div id="tabs">
					<ul>
						<li>
							<a href="#tabs-1">企业列表</a>
						</li>

					</ul>
		<%-- 
			<form name="searchForm" id="searchForm" method="post"
				action="<%=path%>/enterprise/goEnterprise.action" style="margin:10px 0;">
				企业名称:
				<s:textfield name="condition.varEnterpName"></s:textfield>
				企业类型：
				<s:select name="condition.intTypeId" list="#request.typeTabList"
					listKey="intTypeId" listValue="varTypeName" headerKey=""
					headerValue="—请选择—" />
				<input type="button" id="searchBtn" value="检索">
			</form>
		<s:fielderror></s:fielderror>
		--%>
		
			
				<table class="fullwidth" cellpadding="0" cellspacing="0" id="enterInfoTab">
					<thead>
						<tr>
							<td>
								企业名称
							</td>
							<td>
								企业行业类型
							</td>
							<td>
								企业法人
							</td>
							<td>
								企业许可证
							</td>
							<td>
								联系电话
							</td>
							<td>
								企业邮箱
							</td>
							<td>
								企业联系地址
							</td>
							<td>
								操作
							</td>
						</tr>
						</thead>
                       <tbody>
						<s:iterator value="enterpriseList">
							<tr class="odd">
								<td>
									<s:property value="varEnterpName" />
								</td>
								<td>
									<s:property value="varTypeName" />
								</td>
								<td>
									<s:property value="varEnterpLegalPerson" />
								</td>
								<td>
									<s:if test="varEnterpLicenseImgUrl!=null">
										<img alt="企业许可证"
											src="<s:property value="varEnterpLicenseImgUrl" />" width="76"
											height="53" onclick="javascript:window.open('<s:property value="varEnterpLicenseImgUrl" />');">
									</s:if>
								</td>
								<td>
									<s:property value="varEnterpPhonenum" />
								</td>
								<td>
									<s:property value="varEnterpEmail" />
								</td>
								<td>
									<s:property value="varEnterpAddress" />
								</td>
								<td>
									<a  class="icon icon_edit" title="编辑 " href="javascript:editEnter('<s:property value="intEnterpId" />')"></a>
									<%-- 
									<a class="icon icon_delete" title="删除 " href="javascript:delEnter('<s:property value="intEnterpId" />')"></a>
									--%>
									<a  class="icon icon_house" title="查看门店 " href="javascript:getEnterShop('<s:property value="intEnterpId" />')"></a>									
								</td>

							</tr>
						</s:iterator>
					</tbody>
				</table>
				</div>
				<!-- 分页标签开始 -->
				<div align="right" style="float: right;">
					<d:page id="page" template="details" skin="gray">
					</d:page>
				</div>
				<!-- 分页标签结束 -->			
		</div>
		</div>

		<!-- 编辑页使用的弹出层 -->
		<div id="openEnterDialog" style="display: none;">
			<form action="<%=path%>/enterprise/doEditEnterprise.action"
				method="post" id="editEnterForm" enctype=multipart/form-data>
				<s:hidden name="enterpriseDto.intEnterpId" id="intEnterpId"></s:hidden>
				<table class="fullwidth" cellpadding="0" cellspacing="0" border="1">
					<tr>
						<td>
							企业名称
						</td>
						<td>
							<s:textfield name="enterpriseDto.varEnterpName"
								id="varEnterpName"></s:textfield>
							<span style="color: red">*</span>
						</td>
					</tr>
					<tr>
						<td>
							企业行业类型
						</td>
						<td>
							<s:select name="enterpriseDto.intTypeId" id="intTypeId"
								list="#request.typeTabList" listKey="intTypeId"
								listValue="varTypeName" headerKey="" headerValue="—请选择—" />
							<span style="color: red">*</span>
						</td>
						<td>
							企业法人
						</td>
						<td>
							<s:textfield name="enterpriseDto.varEnterpLegalPerson"
								id="varEnterpLegalPerson"></s:textfield>
							<span style="color: red">*</span>
						</td>
					</tr>
					<tr>
						<td>
							企业许可证
						</td>
						<td>
							<img src="" id="imgFile" width="54" height="32">
							<s:file name="myFile" id="file" onblur="validateFile(this)"></s:file>
							<span style="color: red">*</span>
						</td>
					</tr>
					<tr>
						<td>
							联系电话
						</td>
						<td>
							<s:textfield name="enterpriseDto.varEnterpPhonenum"
								id="varEnterpPhonenum"></s:textfield>
							<span style="color: red">*</span>
						</td>

						<td>
							企业邮箱
						</td>
						<td>
							<s:textfield name="enterpriseDto.varEnterpEmail"
								id="varEnterpEmail"></s:textfield>
							<span style="color: red">*</span>
						</td>
					</tr>
					<tr>
						<td>
							企业联系地址
						</td>
						<td>
							<s:textfield name="enterpriseDto.varEnterpAddress"
								id="varEnterpAddress"></s:textfield>
							<span style="color: red">*</span>
						</td>
					</tr>
				</table>

			</form>
		</div>

	</body>
</html>
